
*************************************************
* Replication file Erlandsen, Matthias; Hernández-Garza, María; and Carsten-Andreas Schulz.
* "Madame President, Madame Ambassador? Women Presidents and Gender Parity in Latin America’s Diplomatic Services." 
* Accepted for publication in Political Research Quarterly (February 3, 2021).
*************************************************

* Optional: Install user written commands
ssc install blindschemes, replace 
set scheme plotplainblind
ssc install estout, replace
net install grc1leg, from(http://www.stata.com/users/vwiggins)

* Counting the total number of women ambassadors and calculating proportion
sort surname firstname
quietly by surname firstname: gen dup = cond(_N==1,0,_n)
gen dup_count = 1 if dup <= 1
sum dup_count
gen dup_count_women = 1 if dup <= 1 & ambassador == 1
sum dup_count_women
drop dup dup_count dup_count_women

* Generate variables for total number of appointments, total number of women ambassadors, and yearly percentage of women embassadors (total and per country)
gen bin = 1 if ambassador !=.
sort year
by year: egen yearly_total = total(bin)
by year: egen yearly_total_women = total(ambassador)
by year: gen women_percent_all = yearly_total_women/yearly_total

sort sending_country year
by sending_country year: egen yearly_total_country = total(bin)
by sending_country year: egen yearly_total_women_country = total(ambassador)
by sending_country year: gen women_percent_country = (yearly_total_women_country/yearly_total_country)*100
label variable women_percent_country "Women ambassadors (%)"

sort sending_country year
gen bin_appoint = 1 if appoint !=.
by sending_country year: egen appoint_total_country = total(bin_appoint)
by sending_country year: egen appoint_political_country = total(appoint)
by sending_country year: gen pol_appoint_percent = (appoint_political_country/appoint_total_country)*100
drop bin_appoint

*  Figure 1: Proportion of women ambassadors by country
twoway (lfit women_percent_country year, lcolor(gs12) lpattern(solid))(line women_percent_country year, lcolor(black) lpattern(solid)), by(sending_country, note("") legend(on)) ylabel(0(10)50) ytitle("") xtitle("") subtitle(,nobox)

* Figure 2: Four Latin American countries with women-led governments
sort sending_country year receiving_country
twoway (line pol_appoint_percent year if sending_country == "Argentina", color(gs6) lpattern(dash))(line women_percent_country year, lpattern(l) lcolor(black)) (scatteri 0 2007 0 2015, recast(area) color(gs10%30) lwidth(none))(scatteri 100 2007 100 2015, recast(area) color(gs10%30) lwidth(none)) if sending_country == "Argentina", title("Argentina") xtitle("") legend(lab(4 "Period of women-led government") lab(1 "Discretionary appointments (%)") lab(2 "Women ambassadors (%)") order(1 4 2) cols(2)) name(g1, replace)
twoway (scatteri 0 2006 0 2010, recast(area) color(gs10%30) lwidth(none))(scatteri 100 2006 100 2010, recast(area) color(gs10%30) lwidth(none))(scatteri 0 2014 0 2018, recast(area) color(gs10%30) lwidth(none))(scatteri 100 2014 100 2018, recast(area) color(gs10%30) lwidth(none))(line pol_appoint_percent year if sending_country == "Chile", color(gs6) lpattern(dash)) (line women_percent_country year, lpattern(l) lcolor(black)) if sending_country == "Chile", title("Chile") xtitle("") name(g2, replace)
twoway (scatteri 0 2011 0 2016, recast(area) color(gs10%30) lwidth(none))(scatteri 100 2011 100 2016, recast(area) color(gs10%30) lwidth(none)) (line pol_appoint_percent year if sending_country == "Brazil", color(gs6) lpattern(dash)) (line women_percent_country year, lpattern(l) lcolor(black)) if sending_country == "Brazil",title("Brazil") xtitle("") name(g3, replace)
twoway (scatteri 0 2010 0 2014, recast(area) color(gs10%30) lwidth(none))(scatteri 100 2010 100 2014, recast(area) color(gs10%30) lwidth(none)) (line pol_appoint_percent year, color(gs6) lpattern(dash)) (line women_percent_country year, lpattern(l) lcolor(black)) if sending_country == "Costa Rica", title("Costa Rica") xtitle("") name(g4, replace)
grc1leg g1 g3 g2 g4, legendfrom(g1) name(g5, replace)
graph display g5, xsize(6) ysize(5)

* Summary statistics
format hog ambassador left appoint fminister cabinet admin_age education labor gdp_pp cinc_top25 %9.2f
sum ambassador hog left appoint fminister cabinet admin_age education labor gdp_pp cinc_top25, format

* Logit panel models with year and country fixed effects
xtset embassy_id_num year
xtlogit ambassador i.hog i.ccode i.year, or nolog
estimates store main1
xtlogit ambassador i.left i.ccode i.year, or nolog
estimates store main2
xtlogit ambassador i.appoint i.ccode i.year, or nolog
estimates store main3
xtlogit ambassador i.hog i.left i.appoint i.ccode i.year, or nolog
estimates store main4
xtlogit ambassador i.hog##i.left i.hog##i.appoint i.left##i.appoint i.ccode i.year, or nolog
estimates store main5
xtlogit ambassador i.hog##i.left i.hog##i.appoint i.left##i.appoint fminister cabinet admin_age i.ccode i.year, or nolog
estimates store main6
xtlogit ambassador i.hog##i.left i.hog##i.appoint i.left##i.appoint fminister cabinet admin_age education labor gdp_pp i.ccode i.year, or nolog
estimates store main7
xtlogit ambassador i.hog##i.left i.hog##i.appoint i.left##i.appoint fminister cabinet admin_age education labor gdp_pp cinc_top25 i.ccode i.year, or nolog
estimates store main8
esttab main1 main2 main3 main4 main5 main6 main7 main8, aic eform drop(*.ccode *.year)

*Postestimation
margins hog#left, at (appoint=(0 1))
marginsplot, by(hog) plot1opts(lcolor(gs10) mcolor(gs10)) ci1opts(lcolor(gs10)) plot2opts(lcolor(black) mcolor(black)) ci2opts(lcolor(black)) subtitle(,nobox) ylabel(0(0.1)0.4) ytitle(Probability of Female Ambassador) xlabel(0  "Career" 1  "Discretionary") plotregion(margin(large)) legend(col(2) label(1 "Non-Left") label(2 "Left"))


*************************************************
********************* APPENDIX ******************
*************************************************

* Number of appointments by country
twoway bar yearly_total_country  year, by(sending_country, note("")) xtitle("") color(gs10) barw(0.75) lwidth(none)|| bar yearly_total_women_country year, by(sending_country) color(black) barw(0.75) lwidth(none)subtitle(,nobox) legend(label(1 "Total") label(2 "Women") size(vsmall)) ylabel(0(25)150)

* Correlation matrix
pwcorr ambassador hog left appoint fminister cabinet admin_age education labor gdp_pp cinc_top25, sig
* output: mkcorr ambassador hog left appoint fminister cabinet admin_age education labor gdp_pp cinc_top25, log(corrmatrix)

* Logit models: Models 9-12 introduce interaction terms stepwise; model 13 includes percentage of women in parliament as additional control
xtlogit ambassador i.hog##i.left appoint fminister cabinet admin_age education labor gdp_pp cinc_top25 i.ccode i.year, or nolog
estimates store m9
xtlogit ambassador i.hog i.left i.hog##i.appoint fminister cabinet admin_age education labor gdp_pp cinc_top25 i.ccode i.year, or nolog
estimates store m10
xtlogit ambassador i.hog##i.left i.hog##i.appoint fminister cabinet admin_age education labor gdp_pp cinc_top25 i.ccode i.year, or nolog
estimates store m11
xtlogit ambassador i.hog##i.left i.hog##i.appoint i.left##i.appoint fminister cabinet admin_age education labor gdp_pp cinc_top25 i.ccode i.year, or nolog
estimates store m12
xtlogit ambassador i.hog##i.left i.hog##i.appoint i.left##i.appoint fminister cabinet admin_age education labor gdp_pp cinc_top25 women_parl  i.ccode i.year, or nolog
estimates store m13
esttab m9 m10 m11 m12 m13, aic eform drop(*.ccode *.year)

* Logit models 1-8 with only first years of ambassadorial appointment
* Create embassador_yr variable
sort surname firstname receiving_country
egen embassador_id = group(surname firstname receiving_country)
sort embassador_id admin_id 
by embassador_id admin_id: gen embassador_yr = _n
xtset embassy_id_num year
xtlogit ambassador i.hog i.ccode i.year if embassador_yr == 1, or nolog
estimates store m14
xtlogit ambassador i.left i.ccode i.year if embassador_yr == 1, or nolog
estimates store m15
xtlogit ambassador i.appoint i.ccode i.year if embassador_yr == 1, or nolog
estimates store m16
xtlogit ambassador i.hog i.left i.appoint i.ccode i.year if embassador_yr == 1, or nolog
estimates store m17
xtlogit ambassador i.hog##i.left i.hog##i.appoint i.left##i.appoint i.ccode i.year if embassador_yr == 1, or nolog
estimates store m18
xtlogit ambassador i.hog##i.left i.hog##i.appoint i.left##i.appoint fminister cabinet admin_age i.ccode i.year if embassador_yr == 1, or nolog
estimates store m19
xtlogit ambassador i.hog##i.left i.hog##i.appoint i.left##i.appoint fminister cabinet admin_age education labor gdp_pp i.ccode i.year if embassador_yr == 1, or nolog
estimates store m20
xtlogit ambassador i.hog##i.left i.hog##i.appoint i.left##i.appoint fminister cabinet admin_age education labor gdp_pp cinc_top25 i.ccode i.year if embassador_yr == 1, or nolog
estimates store m21
esttab m14 m15 m16 m17 m18 m19 m20 m21, aic eform drop(*.ccode *.year)

* Logit models with different measures of host countries' status: UNSC permanent member (P5), G7 member (g7), and rank in terms of relative material capabilities (cinc_top10 and top25) and size of its economy (gdp_constant2010_receiving)
xtset embassy_id_num year
xtlogit ambassador i.hog##i.left i.hog##i.appoint i.left##i.appoint fminister cabinet admin_age education labor gdp_pp p5 i.ccode i.year, or nolog
estimates store m22
xtlogit ambassador i.hog##i.left i.hog##i.appoint i.left##i.appoint fminister cabinet admin_age education labor gdp_pp g7 i.ccode i.year, or nolog
estimates store m23
xtlogit ambassador i.hog##i.left i.hog##i.appoint i.left##i.appoint fminister cabinet admin_age education labor gdp_pp cinc_top10 i.ccode i.year, or nolog
estimates store m24
xtlogit ambassador i.hog##i.left i.hog##i.appoint i.left##i.appoint fminister cabinet admin_age education labor gdp_pp cinc_top25 i.ccode i.year, or nolog
estimates store m25
xtlogit ambassador i.hog##i.left i.hog##i.appoint i.left##i.appoint fminister cabinet admin_age education labor gdp_pp cinc_rank_receiving i.ccode i.year, or nolog
estimates store m26
xtlogit ambassador i.hog##i.left i.hog##i.appoint i.left##i.appoint fminister cabinet admin_age education labor gdp_pp gdp_constant2010_receiving i.ccode i.year, or nolog
estimates store m27
esttab m22 m23 m24 m25 m26 m27, aic eform drop(*.ccode *.year)








